/// <reference path="../typings/index.d.ts" />
/// <reference path="../src/bankService.ts" />
/// <reference path="../src/tms.ts" />

describe('getBankList',() => {
    var injector:ng.auto.IInjectorService;
    var service:IBankService;

    beforeEach(() => {
        injector = angular.injector(['ng','tms']);
        service = injector.get<IBankService>('bankService');
    });

    //常规无条件获取
    it('get bank list normal',(done) => {
        service.getList(null, null, null, null, 0, 10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('||||0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取车辆编号包含1的银行列表
    it('get bank list by carId \'1\'',(done) => {
        service.getList('1',null,null,null,0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('1||||0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取承运商编号包含2的银行列表
    it('get bank list by carrierId \'2\'',(done) => {
        service.getList(null,'2',null,null,0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('|2|||0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取银行卡号包含3的银行列表
    it('get bank list by bankCode \'3\'',(done) =>{
        service.getList(null,null,'3',null,0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('||3||0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取车场查询的银行列表
    it('get bank list by isVehicle \'true\' ',(done) => {
        service.getList(null,null,null,true,0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('|||true|0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取 车辆编号包含1,承运商编号包含2 银行卡号包含3,车场查询 的银行列表
    it('get bank list by  carId \'1\' and carrierId \'2\' and bankCode \'3\' and isVehicle \'true\' ',(done) =>{
        service.getList('1','2','3',true,0,10).then((res) => {
            expect(res.data.total).toBe(10);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('1|2|3|true|0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取账户详情
    it('get detail',(done)=>{
        service.getDetail('1').then((res)=>{
            expect(res.data.id).toBe("detail");
            expect(res.data.index).toBe(2);
            expect(res.data.bank).toBe("工商银行");
            expect(res.data.cardNumber).toBe("62220100");
            expect(res.data.holder).toBe("洋洋");
            done();
        },(err)=>{
            done.fail(err);
        });
    });

    //添加银行卡
    it('add bank ',(done)=>{
        service.add('江苏省农村信用社联合社','6230661031001814524','杨杨','1','苏L').then((res)=>{
            expect(res.data.extData).toBe("江苏省农村信用社联合社|6230661031001814524|杨杨|1|苏L");
            done();
        },(err)=>{
            done.fail(err);
        });
    });

    //删除 银行卡编号6230661031001814521，车辆ID 3 的银行卡
    it('delete bank by id \'6230661031001814521\' and vehicleID \'3\' ',(done)=>{
        service.delete('6230661031001814521','3',null).then((res)=>{
            expect(res.data.extData).toBe("6230661031001814521|3|");
            done();
        },(err)=>{
            done.fail(err);
        });
    });

    //删除 银行卡编号6230661031001814521，承运商ID 2 的银行卡
    it('delete bank by id \'6230661031001814521\'and carrierID \'2\' ',(done)=>{
        service.delete('6230661031001814521',null,'2').then((res)=>{
            expect(res.data.extData).toBe("6230661031001814521||2");
            done();
        },(err)=>{
            done.fail(err);
        });
    });

    //获取银行卡信息
    it('get bankName',(done)=>{
        service.getBankName('6230661031001814521').then((res)=>{
            expect(res.data).toBe("6230661031001814521");
            done();
        },(err)=>{
            done.fail(err);
        });
    });

});